package com.shuang.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;

import com.shuang.common.util.StringUtil;
import com.shuang.pojo.SsoLocalUser;
import com.shuang.pojo.SsoUsers;
import com.shuang.service.ServerService;
import com.shuang.service.SsoLocalUserService;
import com.shuang.service.SsoUsersService;

@Service("serverService")
public class ServerServiceImpl implements ServerService{

	@Resource(name="ssoUsersService")
	private SsoUsersService ssoUsersService;
	
	@Resource(name="ssoLocalUserService")
	private SsoLocalUserService ssoLocalUserService;
	@Override
	public String addLocaluser(Map<String,Object> userinfo) throws IllegalAccessException, InvocationTargetException {
		//实例化用户对象
		SsoUsers ssoUsers=new SsoUsers();
		SsoLocalUser ssoLocalUser=new SsoLocalUser();
		//接收的数据映射到实体类
		BeanUtils.copyProperties(ssoUsers, userinfo);
		BeanUtils.copyProperties(ssoLocalUser, userinfo);
		//设置用户基本信息表id 并进行添加
		ssoUsers.setId(UUID.randomUUID().toString());
		ssoUsers =ssoUsersService.addSsoUsers(ssoUsers);
		
		if(StringUtil.notNull(ssoUsers.getId())){
			ssoLocalUser.setUserid(ssoUsers.getId());
			ssoLocalUser=ssoLocalUserService.addSsoLocalUser(ssoLocalUser);
			
			return ssoLocalUser.getUsername();
		}
		return null;
	}

}
